package cn.zhoujing.security.demo.service.impl;

import cn.zhoujing.security.demo.common.enums.StatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.zhoujing.security.demo.entity.PermissionInfo;
import cn.zhoujing.security.demo.service.PermissionInfoService;
import cn.zhoujing.security.demo.mapper.PermissionInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author JingZhou
 * @description 针对表【permission_info】的数据库操作Service实现
 * @createDate 2024-02-12 22:51:55
 */
@Service
public class PermissionInfoServiceImpl extends ServiceImpl<PermissionInfoMapper, PermissionInfo>
        implements PermissionInfoService {

    /**
     * 获取已启用的权限路由列表
     * @return 已启用的权限路由列表
     */
    @Override
    public Set<String> getEnableUris() {
        LambdaQueryWrapper<PermissionInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .select(PermissionInfo::getPermissionUri)
                .eq(PermissionInfo::getActiveStatus, StatusEnum.ENABLE.getCode());
        List<PermissionInfo> list = super.list(queryWrapper);

        if (CollectionUtils.isEmpty(list)) {
            return new HashSet<>();
        }
        return list.stream().map(PermissionInfo::getPermissionUri).collect(Collectors.toSet());
    }

}




